/**
 * 
 */
package com.wangsaichao.cas.config;

import java.util.HashMap;
import java.util.Map;

import org.jasig.cas.client.session.SingleSignOutFilter;
import org.jasig.cas.client.session.SingleSignOutHttpSessionListener;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author qinyinling
 *
 */
@Configuration
public class CasConfig {
	@Bean
	public ServletListenerRegistrationBean<SingleSignOutHttpSessionListener> getServletListenerRegistrationBean(){
		ServletListenerRegistrationBean<SingleSignOutHttpSessionListener> listener=new ServletListenerRegistrationBean<SingleSignOutHttpSessionListener>(new SingleSignOutHttpSessionListener());
	    return listener;
	}
	@Bean
    public FilterRegistrationBean<SingleSignOutFilter> registerAuthFilter() {
        FilterRegistrationBean<SingleSignOutFilter> registration = new FilterRegistrationBean<SingleSignOutFilter>();
        SingleSignOutFilter logoutFilter=new SingleSignOutFilter();
        logoutFilter.setCasServerUrlPrefix("https://sso.demo.com:8443/cas");
		registration.setFilter(logoutFilter);
        registration.addUrlPatterns("/*");
        registration.setName("logoutFilter22");
        registration.setOrder(1);  //值越小，Filter越靠前。
        Map<String, String> initParameters=new HashMap();
        initParameters.put("casServerUrlPrefix", "https://sso.demo.com:8443/cas");
		registration.setInitParameters(initParameters);
        return registration;
    }
}
